package com.javasm.sys;

import cn.hutool.http.useragent.UserAgent;
import cn.hutool.http.useragent.UserAgentUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.javasm.commons.util.IpToAddressUtil;
import com.javasm.commons.util.LogUtils;
import com.javasm.commons.util.ServletUtils;
import com.javasm.commons.util.SpringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;

@Component
public class LogMsgUtil {
    private static final Logger logger = LoggerFactory.getLogger(LogMsgUtil.class);

    public static void recordLogin(LoginUser u,String message, Object... args) {
        //封装登录信息
        SysLoginLog sysLoginLog = new SysLoginLog();
        sysLoginLog.setLoginTime(new Date());
        sysLoginLog.setBrowser(u.getBrowser());
        sysLoginLog.setIpaddr(u.getIp());
        sysLoginLog.setOs(u.getOs());
        sysLoginLog.setMsg(message);
        sysLoginLog.setUserName(u.getUser().getUserName());
        //插入数据
        SpringUtil.getBean(SysLoginLogService.class).insertSelective(sysLoginLog);
    }
}
